<?php require_once('connections/con_gl.php'); require_once("excel/excelwriter.class.php");
?>
<?php
cekAkses($_SESSION[akses],"DD-6");
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_data = 8;
$pageNum_data = 0;
if (isset($_GET['pageNum_data'])) {
  $pageNum_data = $_GET['pageNum_data'];
}
$startRow_data = $pageNum_data * $maxRows_data;
$cr_tgl = $_REQUEST[cr_tgl];
$cr_txt = str_replace("+"," ",$_REQUEST[cr_txt]);
mysql_select_db($database_con_gl, $con_gl);
$query_data = "SELECT no_ref, tgl, keterangan FROM gl_rtrans where jenis='1'";
if(!strstr($_SESSION[akses],'A-1-4')) {
	$query_data .= " AND gudang='$_SESSION[lokasi]'";
}
if($cr_txt <>'') {
	$query_data .=" AND (no_ref LIKE '%%$cr_txt%%' OR keterangan LIKE '%%$cr_txt%%' OR tgl LIKE '%%$cr_txt%%')";
	$query_jurnal .= "AND (gl_rtrans.no_ref LIKE '%%$cr_txt%%' OR gl_rtrans.keterangan LIKE '%%$cr_txt%%' OR gl_rtrans.tgl LIKE '%%$cr_txt%%')";
}
if($cr_tgl <>'' AND $cr_tgl<>'Tanggal...') {
$query_data .=" AND tgl='$_GET[cr_tgl]'";
}
$query_data .=" ORDER BY no_ref desc";
$data = mysql_query($query_data, $con_gl) or die(mysql_error());
$totalRows_data = mysql_num_rows($data);

$totalPages_data = floor($totalRows_data / $maxRows_data);

$query_data .=" LIMIT $startRow_data, $maxRows_data";
$data = mysql_query($query_data, $con_gl) or die(mysql_error());
$totalRow_data = mysql_num_rows($data);
$row_data = mysql_fetch_assoc($data);

$queryString_data = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_data") == false && 
        stristr($param, "totalRows_data") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_data = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_data = sprintf("&totalRows_data=%d%s", $totalRows_data, $queryString_data);
// Export Excel
$excel=new ExcelWriter("report_transaksiharian.xls");
if($excel==false)	
echo $excel->error;

$myArr=array("Tanggal","No Referensi","Total","Keterangan");
$excel->writeLine($myArr);

$qry=mysql_query($query_data, $con_gl);
if($qry!=false)
{
	$i=1;
	while($res=mysql_fetch_array($qry))
	{
		$total = mysql_query("select sum(total) as total from gl_trans where pos='D' AND no_ref='$res[no_ref]'",$con_gl);
		$row_total = mysql_fetch_assoc($total);
		$myArr=array($res['tgl'],$res['no_ref'],$row_total['total'],$res['keterangan']);
		$excel->writeLine($myArr);
		$i++;
	}
}
// End Export
include('include/widget_exportall.php');
?>
<link href="ccss/ui.datepicker.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="js/ui.datepicker.js"></script>
<script type="text/javascript">
<!--
$(function()
      {
        $('.calendar').datepicker({
            appendText : "",
            dateFormat : 'yy/mm/dd'
          });
      });
</script>
<link rel="stylesheet" type="text/css" href="css/lightwindow.css" />
<script type="text/javascript" src="javascript/prototype.js"></script>
<script type="text/javascript" src="javascript/effects.js"></script>
<script type="text/javascript" src="javascript/lightwindow.js"></script>
<script language="javascript">
function download()
{
	window.location='report_transaksiharian.xls';
}
</script>
<h1>Daftar Transaksi Harian</h1>
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable">
  <tr class="hide">
    <td><?php if(strstr($_SESSION['akses'],"DD-6-1")) { ?><a href="index.php?component=transaksiharian&amp;task=add"><img src="images/add_new.png" border="0" /></a><?php } ?></td>
    <td>&nbsp;</td>
    <td colspan="3" align="right"><form id="search" name="search" method="post" action="">
      <label>
      <input name="cr_tgl" type="text" id="cr_tgl" value="<?php if(empty($_GET[cr_tgl])) echo "Tanggal...";else echo $_GET[cr_tgl];?>"onblur="if(this.value=='') this.value='Tanggal...';" onfocus="if(this.value=='Tanggal...') this.value='';" size="10" maxlength="10" class="calendar"/>
      </label>
      <label>
      <input name="cr_txt" type="text" id="cr_txt" value="<?php echo $cr_txt;?>" size="30" maxlength="100"/>
      </label>
      <label>
      <input name="Search" type="submit" id="Search" value="Search" />
      </label>
    </form><?php
	if(isset($_POST['Search'])) {
		echo "<script>window.location=\"index.php?component=transaksiharian&cr_tgl=".$_POST[cr_tgl]."&cr_txt=".str_replace(" ","+",$_POST[cr_txt])."\";</script>";
	}
	?></td>
  </tr>
  <tr>
    <th width="10%"><strong>Tanggal</strong></th>
    <th width="18%"><strong>No Referensi</strong></th>
    <th><strong>Keterangan</strong></th>
    <th width="8%" align="center"><strong>Status</strong></th>
    <th width="195" align="center" class="hide"><strong>Aksi</strong></th>
  </tr>
  <?php if($totalRows_data > 0) { ?>
  <?php do { ?>
  <?php
  mysql_select_db($database_con_gl, $con_gl);
$query_getd = "SELECT sum(total) FROM gl_trans WHERE pos = 'D' AND no_ref='$row_data[no_ref]'";
$getd = mysql_query($query_getd, $con_gl) or die(mysql_error());
$row_getd = mysql_fetch_assoc($getd);
$totalRows_getd = mysql_num_rows($getd);

mysql_select_db($database_con_gl, $con_gl);
$query_getk = "SELECT sum(total) FROM gl_trans WHERE pos = 'K' AND no_ref='$row_data[no_ref]'";
$getk = mysql_query($query_getk, $con_gl) or die(mysql_error());
$row_getk = mysql_fetch_assoc($getk);
$totalRows_getk = mysql_num_rows($getk);

  ?>
  <tr valign="top" bgcolor="#FFFFFF">
    <td align="center"><?php tanggal($row_data['tgl'],"tampilkan"); ?></td>
    <td align="center"><?php echo $row_data['no_ref']; ?></td>
    <td><?php echo $row_data['keterangan']; ?></td>
    <td align="center"><?php if($row_getd['sum(total)'] == $row_getk['sum(total)'] AND $row_getd['sum(total)'] > 0) { ?>
        <img src="images/ok.png" width="16" height="16" title="Jurnal Balance"/>
      <?php }else{ ?>
      <img src="images/alert.png" width="16" height="16" title="Jurnal Salah / Tidak Balance"/>
      <?php } ?></td>
    <td align="center" class="hide"><a href="include/jurnalvoucher.php?referensi=<?php echo $row_data['no_ref'];?>" onclick="NewWindow(this.href,'name','940','300','yes');return false" title="Jurnal Voucher"><img src="images/jurnal_.png" border="0" /></a> <?php if(strstr($_SESSION['akses'],"DD-6-2")) { ?><a href="index.php?component=transaksiharian&amp;task=edit&amp;referensi=<?php echo $row_data[no_ref];?>"><img src="images/edit_.png" border="0" /></a><?php } ?> <?php if(strstr($_SESSION['akses'],"DD-6-3")) { ?><a href="index.php?component=transaksiharian&amp;task=delete&amp;referensi=<?php echo $row_data[no_ref];?>" class="ask"><img src="images/delete_.png" border="0" /></a><?php } ?></td>
  </tr>
    <?php } while ($row_data = mysql_fetch_assoc($data)); ?>
	<?php if($totalRows_data > $maxRows_data) { ?>
    <tr class="hide">
      <td colspan="10"><table border="0" align="left" width="50%">
          <tr>
            <td width="3%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, 0, $queryString_data); ?>"><img src="First.gif" border=0 ></a>
                <?php } // Show if not first page ?>            </td>
            <td width="3%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, max(0, $pageNum_data - 1), $queryString_data); ?>"><img src="Previous.gif" border=0></a>
                <?php } // Show if not first page ?>            </td>
            <td width="3%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, min($totalPages_data, $pageNum_data + 1), $queryString_data); ?>"><img src="Next.gif" border=0></a>
                <?php } // Show if not last page ?>            </td>
            <td width="3%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, $totalPages_data, $queryString_data); ?>"><img src="Last.gif" border=0></a>
                <?php } // Show if not last page ?>            </td>
			<td width="88%">Halaman : <?php echo $pageNum_data+1; ?>, Ditampilkan <?php echo $totalRow_data; ?> dari <?php echo $totalRows_data; ?> total data</td>
          </tr>
        </table></td>
    </tr>
	<?php } ?>
   <?php }else{ ?>
  <tr bgcolor="#FFFFFF">
    <td colspan="5">Data tidak ada !!! </td>
  </tr>
  <?php } ?>
  <tr class="hide">
    <td colspan="5"><a href="index.php?component=transaksiharian&amp;task=add"><img src="images/add_new.png" border="0" /></a>
      </td>
  </tr>
</table>